package cn.hotel.service;

import cn.hotel.dao.LogDao;
import cn.hotel.pojo.Log;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class LogServiceImpl implements LogService{

    cn.hotel.dao.Log log = new LogDao();
    @Override
    public Map<String, Object> logMap(String operator, int atPresent, int sum) {
        Map<String ,Object> logs = new HashMap<>();
        int num = (atPresent - 1) * sum;
        try {
            List<Log> logList = log.logList(operator, num, sum);
            if(logList != null && logList.size() > 0){
                logs.put("flag","1");
                logs.put("mag","查询成功");
                logs.put("data",logList);
            }else {
                logs.put("flag","0");
                logs.put("mag","查询失败");
            }
        } catch (Exception exception) {
            exception.printStackTrace();
            logs.put("flag","-1");
            logs.put("mag","程序异常");
        }
        return logs;
    }

    @Override
    public Map<String, Object> elaboration(String operator) {
        Map<String ,Object> logs = new HashMap<>();
        try {
            int logList = log.elaboration(operator);
            if(logList > -1){
                logs.put("flag","1");
                logs.put("mag","查询成功");
                logs.put("data",logList);
            }else {
                logs.put("flag","0");
                logs.put("mag","查询失败");
            }
        } catch (Exception exception) {
            exception.printStackTrace();
            logs.put("flag","-1");
            logs.put("mag","程序异常");
        }
        return logs;
    }

    @Override
    public Map<String, Object> addLog(String operator, String content) {
        Map<String ,Object> logs = new HashMap<>();
        try {
            int num = log.addLog(operator, content);
            if(num > 0){
                logs.put("flag","1");
                logs.put("mag","添加成功");
            }else {
                logs.put("flag","0");
                logs.put("mag","添加失败");
            }
        } catch (Exception exception) {
            exception.printStackTrace();
            logs.put("flag","-1");
            logs.put("mag","程序异常");
        }
        return logs;
    }

    @Override
    public Map<String, Object> deleteLog(String operator) {
        Map<String ,Object> logs = new HashMap<>();

        try {
            int num = log.deleteLog(operator);
            if(num > 0){
                logs.put("flag","1");
                logs.put("mag","删除成功");
            }else {
                logs.put("flag","0");
                logs.put("mag","删除失败");
            }
        } catch (Exception exception) {
            exception.printStackTrace();
            logs.put("flag","-1");
            logs.put("mag","程序异常");
        }
        return logs;
    }
}
